<template> 
  <div class="cmt-container">
    <h3>
      发表评论
    </h3>
    <textarea placeholder="请输入要BB的内容(最多180字)" maxlength="180"></textarea>
   <mt-button type="primary" size="large">发表评论</mt-button>
   <div class="cmt-list" v-for="(item,index) in commentsList" :key="index">
     <div class="cmt-item">
       <div class="cmt-title">
         第{{index+1}}楼&nbsp;&nbsp;用户:{{item.user_name}}&nbsp;&nbsp;发表时间:{{item.add_time|dateFormat}}
       </div>
       <div class="cmt-body">
         {{item.content?item.content:"评论为空"}}
       </div>
     </div>
   </div>
   <mt-button type="danger" size="large" plain @click="listMore" v-show="flage">加载更多</mt-button>
  </div>
</template>
<script>
import{getComment} from '@/api'
export default {
  data () {
    return {
      flage:true,
      commentsList:[],
     params:{
       id:this.$route.params.id,
       pageindex:1,
     }
    }
  },  
  created(){
    this.init() 
  },
  methods:{
    init(){
      getComment(this.params).then(res=>{
         console.log(res);
        if(res.message.length !== 0?this.flage=true:this.flage=false)
       
        if(res.status === 0){
          this.commentsList = this.commentsList.concat(res.message);
         
        }else{
          Totas('获取评论失败')
        
          
        }
      })
    },
    listMore(){
      this.params.pageindex++,
      this.init()
      
    }
  }
}
</script>
<style lang="scss" scoped>
  .cmt-container{
    h3{
      font-size: 18px;
    }
    textarea{
      font-size: 14px;
      height: 85px;
      margin: 0;
    }
    .cmt-list{
      margin: 5px 0;
      .cmt-item{
        font-size: 13px;
        .cmt-title{
          height: 30px;
          background-color: #ccc;
        }
        .cmt-body{
          line-height: 35px;
          text-indent: 2em;
        }
      }
    }
  }
</style>

